﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TCG
{
    public class Card
    {
        public int Id { get; set; }
        public String Name {get; set;}
        public String ImagePath { get; set; }
        public String Description { get; set; }
        public List<Action> Acts { get; set; }
        public ResourceCount Cost { get; set; }
        public bool IsGray { get; set; }
    }

    public class TCGDeck : List<Card>
    {
        public DeckType Type;
        public Card CardByID(int id)
        {
            return this.Find((a) => { return a.Id == id; });
        }

        public Card RandomCard()
        {
            Random rnd = new Random();
            int cardIndex = rnd.Next(this.Count);
            return this[cardIndex];
        }

        public int RandomCardID()
        {
            return RandomCard().Id;
        }

        public TCGDeck RandomDeck(int count)
        {
            return RandomDeck(count, false);
        }
        public TCGDeck RandomDeck(int count, bool isDistinct)
        {
            TCGDeck d = new TCGDeck();

            for (int i = 0; i < count; i++)
            {
                Card c = RandomCard();
                while (isDistinct && d.Contains(c) && d.Count <= this.Count)
                    c = RandomCard();
                d.Add(c);
            }
            return d;
        }

        public void ValidateCards(ResourceCount rPlayer)
        {
            ValidateCards(this, rPlayer);
        }
        public static void ValidateCards(TCGDeck deck, ResourceCount rPlayer)
        {
            foreach (Card c in deck)
            {
                c.IsGray = false;
                foreach(KeyValuePair<Resource,int> rCost in c.Cost)
                {
                    if (rPlayer[rCost.Key] < rCost.Value)
                    {
                        c.IsGray = true;
                        break;
                    }
                }
            }
        }
    }

    public enum DeckType
    {
        None = 0,
        Unlimited = 1,
        Single = 2
    }

    public class Action
    {
        //public Guid id;
        //public String Description;
        public ActionType Type;
        public object Value;
    }

    public enum ActionType
    { 
        None = 0,
        DoDamage,
        AddHealth,
        AddResource,
        AddSource,
        AbaddonSource
    }

}
